
#include "TbButton.h"

typedef Window* Obj; const int n = 4; //number of buttons

//
class Toolbar: public Window
{
   int i; Obj btns[n]; HIMAGELIST iml, iml1, iml2; TRACKMOUSEEVENT tme;

public:

   //
   void Initialize()
   {
      //list of icons
      HANDLE im = LoadImageA(hinst, MAKEINTRESOURCEA(2), 0, 0, 0, 0);
      iml = ImageList_Create(24, 24, ILC_COLOR24|ILC_MASK, n, 0); ImageList_AddMasked(iml, (HBITMAP)im, RGB(255,0,0));
      im = LoadImageA(hinst, MAKEINTRESOURCEA(3), 0, 0, 0, 0);
      iml1 = ImageList_Create(24, 24, ILC_COLOR24|ILC_MASK, n, 0); ImageList_AddMasked(iml1, (HBITMAP)im, RGB(255,0,0));
      im = LoadImageA(hinst, MAKEINTRESOURCEA(4), 0, 0, 0, 0);
      iml2 = ImageList_Create(24, 24, ILC_COLOR24|ILC_MASK, n, 0); ImageList_AddMasked(iml2, (HBITMAP)im, RGB(255,0,0)); 
      DeleteObject(im); //release temporary im

      //
      tme.cbSize = sizeof(tme); tme.dwFlags = TME_LEAVE; tme.dwHoverTime = 9;

      for(i=0; i<n; i++)
      {
         btns[i] = new TbButton(i, &iml, &iml1, &iml2, &tme);
         btns[i]->Create(this, 0, 0, WS_VISIBLE|WS_CHILD, L"Window", i*24, 0, 24, 24, hwnd, 0);
         if(i)((TbButton*)btns[i])->status = 3; else ((TbButton*)btns[i])->status = 0; //disabled default
         btns[i]->Show(1, 0);
      }
   }

   //
   virtual ~Toolbar()
   { 
      ImageList_Destroy(iml); ImageList_Destroy(iml1); ImageList_Destroy(iml2);
      for(i=0; i<n; i++) delete[] btns[i];
   }

   //
   //int OnUserMessage(UINT m, WPARAM, LPARAM)
   //{ /*if(m == 3333) { for(i=0; i<n; i++) btns[i]->Invalidate(true); }*/ return 0; }

   //
   int OnCommand(WPARAM wp, LPARAM lp)
   {
      switch(LOWORD(wp))
      {

      case 345:

         ((TbButton*)btns[LOWORD(lp)])->status = HIWORD(lp);
         InvalidateHwnd( ((TbButton*)btns[LOWORD(lp)])->hwnd, ((TbButton*)btns[LOWORD(lp)])->over);

         break;

      }
      return 0;
   }


};

